#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
using namespace std;
constexpr int mod=1000000007;
int n,k,a;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define writeln(x) cout<<x<<endl
signed main()
{
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	cin>>n>>k; vector<string> s(n);
	rep(i,0,n-1) cin>>s[i];
	vector<vector<int>> in(n,vector<int>(n)),deg(n,vector<int>(n)),deg_in(n,vector<int>(n));
	rep(i,0,n-1) rep(j,0,n-1) if(s[i][j]=='.')
	{
		int ok=0;
		rep(d,0,3)
		{
			int x=i+dx[d],y=j+dy[d];
			if(x<0||x>=n||y<0||y>=n) continue;
			if(s[x][y]=='#') {ok=1; break;}
		}
		in[i][j]=ok,a+=ok;
	}
	rep(i,0,n-1) rep(j,0,n-1) if(s[i][j]=='.')
	{
		int v=0,v_in=0;
		rep(d,0,3)
		{
			int x=i+dx[d],y=j+dy[d];
			if(x<0||x>=n||y<0||y>=n) continue;
			if(s[x][y]=='.') ++v,v_in+=in[x][y];
		}
		deg[i][j]=v,deg_in[i][j]=v_in;
	}
	if(k==1) writeln(a),exit(0);
	int tot=0;
	rep(i,0,n-1) rep(j,0,n-1) if(s[i][j]=='.'&&in[i][j]) tot+=deg[i][j]-deg_in[i][j];
	if(k==2) writeln((a*(a-1)/2%mod+tot)%mod),exit(0);
	writeln(114514);
	return 0;
}
